﻿using Hue_Demo_PCL.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;

namespace Hue_Demo_WinStore.Converters
{
    public class ColorToOpacity : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value == null)
                return 0.2;

            var colorInt = (int)value;
            var opacity = .2 + (.79 * (colorInt / 255.0));
            return opacity;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            if (value == null)
                return 0;
            var opacity = (double)value;
            var colorInt = System.Convert.ToInt32(((opacity - .2)/.79) * 255);
            return colorInt;
        }
    }

    public class HueLightToColor : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter,string language)
        {
            SolidColorBrush scb = new SolidColorBrush();
            scb.Color = Color.FromArgb(255, 255, 255, 255);
            if (value == null)
                return scb;

            var hueL = (HueLight)value;
            scb.Color = Color.FromArgb(255,
                                System.Convert.ToByte(hueL.Red),
                                System.Convert.ToByte(hueL.Green),
                                System.Convert.ToByte(hueL.Blue));
            return scb;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            return null;
        }
    }
}
